<?php
/**
 * Log.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-09-08 10:22:05
 * @modified    2023-09-08 10:22:05
 *
 */

namespace App\Models\PollingPlan;

use App\Models\BaseModel;
use App\Models\Polling;
use App\Models\PollingPlan;

class Log extends BaseModel
{
    protected $table = 'polling_plan_log';

    protected $primaryKey = 'id';

    public const CREATED_AT = 'create_time';
    public const UPDATED_AT = 'update_time';

    protected $fillable = [
        'polling_plan_id',
        'polling_id',
        'user_id',
        'status'
    ];

    public function scopeByPollingPlanId($query, $pollingPlanId)
    {
        return $query->where('polling_plan_id', $pollingPlanId);
    }

    public function scopeByLatest($query)
    {
        return $query->orderByDesc('create_time');
    }

    public function polling_plan()
    {
        return $this->belongsTo(PollingPlan::class);
    }

    public function polling()
    {
        return $this->belongsTo(Polling::class);
    }
}